/*
package com.common.project.common;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.subway.archives.table.Department;
import com.subway.archives.table.Dictionaries;
import com.subway.archives.table.Station;
import org.apache.commons.lang3.reflect.FieldUtils;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ForeignKeyUtil<T1,T2 extends T1> {

    public static <T1,T2 extends T1> List<T2> setForeignKeyValue(List<T1> t1List,T2 t2){
        List<T2> t2List=new ArrayList<>();
        try {

            for(T1 t:t1List){
                Class<?> childClass = t2.getClass();
                Class<?> fatherClass = t.getClass();
                Field[] fields = fatherClass.getDeclaredFields();

                for(Field field :fields){
                    if(field.isAnnotationPresent(ForeignKey.class)){
                        ForeignKey foreignKey = (ForeignKey) field.getAnnotation(ForeignKey.class);
                        field.setAccessible(true);
                        String tableName = foreignKey.tableName();
                        String columnName = foreignKey.columnName();
                        String columnValue = foreignKey.columnValue();
                        Field columnValueField = childClass.getDeclaredField(columnValue);
                        //获取属性值
                        Object value = field.get(t);
                        if(value==null||"".equals(value.toString())){
                            continue;
                        }

                        Class<?> aClass = Class.forName(tableName);
                        Object o = aClass.newInstance();

                        Object typeValue=null;
                        if(o instanceof Dictionaries){
                            Dictionaries dictionaries = (Dictionaries) o;
                            LambdaQueryWrapper<Dictionaries> dictionariesLambdaQueryWrapper=new LambdaQueryWrapper<>();
                            dictionariesLambdaQueryWrapper.eq(Dictionaries::getId,value)
                                    .eq(Dictionaries::getState,1);

                            Dictionaries varDictionaries = dictionaries.selectOne(dictionariesLambdaQueryWrapper);
                           typeValue = varDictionaries.getTypeValue();
                        }
                        if(o instanceof Department){
                            Department varDepartment = (Department) o;
                            LambdaQueryWrapper<Department> departmentLambdaQueryWrapper=new LambdaQueryWrapper<>();
                            departmentLambdaQueryWrapper
                                    .eq(Department::getDeptId,value)
                                    .eq(Department::getState,1);

                            Department varDepartmentOne = varDepartment.selectOne(departmentLambdaQueryWrapper);
                            typeValue=varDepartmentOne.getName();
                        }
                        if(o instanceof Station){
                            Station station=(Station)o;
                            LambdaQueryWrapper<Station> stationLambdaQueryWrapper=new LambdaQueryWrapper<>();
                            stationLambdaQueryWrapper
                                    .eq(Station::getId,value)
                                    .eq(Station::getState,1);
                            Station varStation = station.selectOne(stationLambdaQueryWrapper);
                            typeValue=varStation.getName();
                        }

                        columnValueField.setAccessible(true);
                        columnValueField.set(t2,typeValue);

                    }
                }

                fatherToChild(t,t2);
                t2List.add(t2);

            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }

        return t2List;

    }




    public static <T1,T2 extends T1> void fatherToChild(T1 t, T2 child) throws Exception {
        Class<?> fatherClass = t.getClass();
        if (child.getClass().getSuperclass()!=fatherClass){
            throw new Exception("child 不是 father 的子类");
        }
        Field[] declaredFields = fatherClass.getDeclaredFields();
        Class<?> childClass = child.getClass();
        Field[] childDeclaredFields = FieldUtils.getAllFields(childClass);

        for (int i = 0; i < declaredFields.length; i++) {
            Field field=declaredFields[i];
            Method method=fatherClass.getDeclaredMethod("get"+upperHeadChar(field.getName()));
            Object obj = method.invoke(t);

            List<Field> collect = Stream.of(childDeclaredFields).filter(field1 -> field1.getName().equals(field.getName())).collect(Collectors.toList());
            if(collect==null||collect.size()==0){
                continue;
            }

            Field field1 = collect.get(0);
            field1.setAccessible(true);
            field1.set(child,obj);
        }

    }

    */
/**
     * 首字母大写，in:deleteDate，out:DeleteDate
     *//*

    public static String upperHeadChar(String in) {
        String head = in.substring(0, 1);
        String out = head.toUpperCase() + in.substring(1, in.length());
        return out;
    }



}
*/
